package com.giveu.signature.module.system.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.giveu.common.fastdfs.service.FastdfsClientService;
import com.giveu.signature.common.constants.FileSuffix;
import com.giveu.signature.common.util.SignFileUtil;
import com.giveu.signature.config.FeignProperties;
import com.giveu.signature.module.template.controller.SignTemplateHtmlController;

@Controller
public class BSCommonController {
	
	private static final Logger log = LoggerFactory.getLogger(SignTemplateHtmlController.class);
	@Autowired
	FeignProperties feignProperties;
	
	@Autowired
	FastdfsClientService fastdfsClientService;

	@SuppressWarnings("serial")
	@RequestMapping("/fastdfs/uploadFile")
	@ResponseBody
	private Map<String, Object> uploadFastdfs(@RequestParam("file") MultipartFile file) {
		Map<String, Object> resultMsg = new HashMap<String, Object>(){{put("success", false);}};
		if (file == null || file.isEmpty()) {
			resultMsg.put("messgae", "上传文件为空");
			return resultMsg;
		}
		try {
			String content = fastdfsClientService.fileUpload(file);
			resultMsg.put("content",content);
			resultMsg.put("fastPath",feignProperties.getFastdfsUrl()+content);
			resultMsg.put("success", true);
		} catch (Exception e) {
			resultMsg.put("messgae", e.getMessage());
		}finally {
		}
		return resultMsg;
	}
}
